import 'package:fish_redux/fish_redux.dart';
import 'action.dart';
import 'state.dart';
import '../../../../app_files.dart';
import '../../model/account_model.dart';

Effect<GasNoSearchResultViewState> buildEffect() {
  return combineEffects(<Object, Effect<GasNoSearchResultViewState>>{
    GasNoSearchResultViewAction.action: _onAction,
    GasNoSearchResultViewAction.onTap: _onTap,
  });
}

void _onAction(Action action, Context<GasNoSearchResultViewState> ctx) {
}

void _onTap(Action action, Context<GasNoSearchResultViewState> ctx) async {
  int res = await CommonUtils.showOKCanceltView(ctx.context, '确定绑定该户号？');
  if (res == 1) {
    AccountItemModel item = action.payload;
    CommonUtils.showLoadingDialog(ctx.context);
    ResultData res = await CommonNetWork.gasNoBlind(accountNo: item.accountNo,userName: item.name);
    Navigator.pop(ctx.context);
    if (res.success) {
      bus.emit('refreshAccountList');
      await CommonUtils.showAlertView(ctx.context, '绑定成功');
      Navigator.pop(ctx.context,'成功');
    }
    else {
      CommonUtils.showErrorInfo(ctx.context, res.desc);
    }
  }
}